Array.prototype.selectionSort = function () {
  for (let i = 0; i < this.length; i++) {
    let minIndex = i
    for (let j = i; j < this.length; j++) {
      if (this[j] < this[minIndex]) {
        minIndex = j
      }
    }
    if (minIndex !== i) {
      const tmp = this[i]
      this[i] = this[minIndex]
      this[minIndex] = tmp   
    }
  }

}

arr = [5,4,3,2,1]
arr.selectionSort()
console.log(arr)